#include <stdio.h>

/* Set symbolic identifiers for word counting */
#define IN 1
#define OUT 0

int main(int argc, char *argv[])
{
  /* Define Variables */
  int w, c, l, d, i, ch, state;
  int digits[10]; /* Creates Array of 10 Values */
  
  /* Set initial values of counting variables for counting stuff*/
  c = d = w = 0;
  l = 1;
  
  for(i = 0; i < 10; ++i){
    digits[i] = 0;
  }
  
  /* Set state variable */
  state = OUT;
  
  /* Loop through each character of the input and count Words, Characters, Lines, & Digits */
  while((ch = getchar()) != EOF){
    if(ch == '\n'){
      l++; /* Increment Line Count */
      state = OUT;
    }
    else{ 
      /* Start Word Count Code */
      if(ch == ' ' || ch == '\t'){
	state = OUT;
      }
      else if(state == OUT){
	state = IN;
	w++; /* Increment Word Count */
      }
      /* End Word Count Code */
      
      c++; /* Increment Character Count (Doesn't count newline characters in the character count) */
    }
    /* Perform Digit Count */
    if(ch >= '0' && ch <= '9'){
      digits[ch - '0']++;
    }
  }
  
  /* Reset Line Count to zero if input was blank */
  if(c < 1){
    l = 0;
  }
  
  /* Print Results */
  printf("\nWords: %d\nCharacters: %d\nLines: %d\n",w,c,l); /* Prints Words, Characters, and Lines */
  
  for(i = 0; i <10; ++i){
    printf("Digit %d: %d\n",i,digits[i]); /* Print Digit Counts */
  }
  
  printf("\n"); /* Add one ending line break to give a space after the output */

  return 0;
}
